<!--修改密码-->
<template>
  <div>
    <el-dialog
      title="密码修改"
      :visible.sync="editUserPwdVisible"
      width="40%"
      :show-close="false"
      :close-on-click-modal="false">
      <el-form ref="editUserPwdForm" :model="editUserPwdForm" :rules="editUserPwdForm_rules" label-width="110px">
        <el-form-item label="新密码" prop="user_password">
          <el-input v-model="editUserPwdForm.user_password" size="small" style="width: 80%"></el-input>
        </el-form-item>

        <el-form-item label="再次输入密码" prop="user_password1">
          <el-input v-model="editUserPwdForm.user_password1" size="small" style="width: 80%"></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="closeEditUserPwd">取 消</el-button>
      <el-button size="mini" type="primary" @click="editUserInfoPwd">确 定</el-button>
    </span>
    </el-dialog>
  </div>
</template>
<script>
  import {getAllUserByGroupId,updateUserByUserId,updateUserPasswordById,findUserByCondition,addUser} from '@/api/user'
  export default{
      props:["isShowUpdatePwdDialog","updatePwdData"],
      data(){
          return {
            editUserPwdVisible:this.isShowUpdatePwdDialog,
            editUserPwdForm:{
                user_password:"",
                user_password1:""
            },
            userPwdData:{},
            editUserPwdForm_rules:{
              user_password:[{ required: true, message: '不能为空', trigger: 'change' },{ min: 5, max: 12, message: '长度在 5 到 12 个字符', trigger: 'blur' }],
              user_password1:[{ required: true, message: '不能为空', trigger: 'change' },{ min: 5, max: 12, message: '长度在 5 到 12 个字符', trigger: 'blur' }]
            }
          }
      },

      mounted(){
          //console.log(this.updatePwdData);
      },

      methods:{
        closeEditUserPwd(){
            this.editUserPwdVisible = false;
            this.$emit("updateUserPwdClose","pwd");
        },
        editUserInfoPwd(){
          this.$refs["editUserPwdForm"].validate((valid) =>{
              if(valid){
                  if(this.editUserPwdForm.user_password == this.editUserPwdForm.user_password1){
                     this.userPwdData.user_password = this.editUserPwdForm.user_password;
                    //调用后台接口进行密码修改
                    updateUserPasswordById(this.userPwdData).then(res=>{
                        if(res.code == 200){
                          this.$message({
                            message: '修改成功',
                            type: 'success'
                          });
                          this.closeEditUserPwd();
                        }
                    });
                  }else{
                    this.$message({
                      message: '两次输入密码不一致',
                      type: 'warning'
                    });
                  }
              }
          });
        }
      }
  }
</script>
